package com.woniu.microassetserver.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.service.VendorManagementService;
import com.woniu.microcommonsserver.entity.ResultMsg;
import com.woniu.microcommonsserver.entity.VendorManagementEntity;
import com.woniu.microcommonsserver.param.PageResult;
import com.woniu.microcommonsserver.param.ResponseMsg;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 
 *
 * @author luoyue
 * @email 1316756108@qq.com
 * @date 2021-01-30
 */
@RestController
@RequestMapping("/vendormanagement")
public class VendorManagementController {

    @Resource
    private VendorManagementService vendorManagementServiceImpl;


    @RequestMapping(value = "/more", produces = {"application/json;charset=utf-8"})
    public ResultMsg saveVendorManagement(VendorManagementEntity vendorManagementEntity) {

        System.out.println("添加");
        ResultMsg resultMsg = new ResultMsg(200, "新增成功", null);
        vendorManagementServiceImpl.saveVendorManagement(vendorManagementEntity);
        System.out.println("新增成功");
        return resultMsg;
    }


    @PutMapping(value = "/id/{id}", produces = {"application/json;charset=utf-8"}) /*AssetsParameterBean assetsParameterBean, @PathVariable("id") Long id*/
    public ResultMsg updatevendorManagement(@PathVariable("id") Long id,VendorManagementEntity vendorManagementEntity) {
        ResultMsg resultMsg = new ResultMsg(200, "更新成功", null);
        System.out.println(id);
        vendorManagementServiceImpl.updateVendorManagement(vendorManagementEntity);
        return resultMsg;
    }


    @DeleteMapping(value = "/delete/{id}", produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteVendorManagement(@PathVariable("id") Long id) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "删除成功", null);

       vendorManagementServiceImpl.deleteVendorManagement(id);

        System.out.println("删除成功");

        return  resultMsg;

    }

    @GetMapping(value = "/selectAll", produces = {"application/json;charset=utf-8"})
    public ResponseMsg selectVendorManagement(Integer pageNum, Integer pageSize,VendorManagementEntity vendorManagementEntity) {

        System.out.println("添加");

        ResultMsg resultMsg = new ResultMsg(200, "查询成功", null);


        PageInfo<VendorManagementEntity> pageInfo =vendorManagementServiceImpl.findAllByParams(pageNum, pageSize, vendorManagementEntity);

        System.out.println(pageInfo);


        PageResult<VendorManagementEntity> pageResult=new PageResult<VendorManagementEntity>();
        pageResult.setRows(pageInfo.getList());
        pageResult.setTotal(pageInfo.getTotal());

        return ResponseMsg.builder().code(200).msg("查询陈工").data(pageResult).build();



    }
}
